package StudyCode.summary.Basic.myint;

import java.util.ArrayList;

/**
 * 版权所有 科技与人文(www.tah1986.com)
 */
public class PolygonArea {
	public static void main(String[] args) {
		ArrayList<Point> vertex = new ArrayList<>();
		vertex.add(new Point(10, 0));
		vertex.add(new Point(10, 10));
		vertex.add(new Point(0, 10));
		vertex.add(new Point(0, 0));
		System.out.println("多边形面积是：" + calculate(vertex));
	}

	private static float calculate(ArrayList<Point> vertex) {
		int i = 0;
		float temp = 0;
		for (; i < vertex.size() - 1; i++) {
			temp += (vertex.get(i).x - vertex.get(i + 1).x) * (vertex.get(i).y + vertex.get(i + 1).y);
		}
		temp += (vertex.get(i).x - vertex.get(0).x) * (vertex.get(i).y + vertex.get(0).y);
		return temp / 2;
	}
}

class Point {
	public int x;
	public int y;

	Point(int x, int y) {
		this.x = x;
		this.y = y;
	}
}
